import * as index from '@/api/index.js'
export default {
	data() {
		return {
			menu: uni.getMenuButtonBoundingClientRect(),
			CustomBar: this.Custom.height,
			token: uni.getStorageSync('token'),
			loginInfo: {
				mobilecode: '',
				code: ''
			}, //登陆参数
			userInfo: {
				mobile: ''
			},
			list: [{
					name: '我的门店',
					image: '/static/user/list1.png',
					url: '/pages/user/myStore/index'
				},
				// {
				// 	name: '门店订单',
				// 	image: '/static/user/list2.png',
				// 	url: '/pages/user/order/index'
				// },
				{
					name: '技师认证',
					image: '/static/user/list3.png',
					url: '/pages/user/authentication/index'
				},
				{
					name: '技师订单',
					image: '/static/user/list4.png',
					url: '/pages/user/jsOrder/index'
				},
				{
					name: '邀请好友',
					image: '/static/user/list5.png',
					open: 'https://wanbang.wanhedashuju.com/uploads/qrcode.jpg'
				},
				{
					name: '业务质询',
					image: '/static/user/list6.png',
					mobile: '0537-6696595'
				},
				{
					name: '我的佣金',
					image: '/static/user/list7.png',
					url: '/pages/user/money/index'
				},
				{
					name: '意见反馈',
					image: '/static/user/fankui.png',
					url: '/pages/user/feedback/index'
				}
			
			],
			list2:[
				{
					name: '质保录入',
					image: '/static/user/zb.png',
					url: '/pages/user/enter/index'
				}
			]
		}
	},

	onShow() {
		this.token = uni.getStorageSync('token')
		this.getUserInfo()
	},
	onLoad(option) {
		// this.token = uni.getStorageSync('token')
	},

	methods: {
		getUserInfo() {
			if (uni.getStorageSync('token')) {
				index.getUserInfo().then(res => {
					this.userInfo = res.data
				})
			}
		},
		jump(item) {
			if (!item.open) {
				if (item.mobile) {
					uni.makePhoneCall({
						phoneNumber: item.mobile //仅为示例
					});
				} else {
					this.$tools.navigate(item.url)
				}
			} else {
				console.log(item);
				uni.previewImage({
					urls: [item.open],
					longPressActions: {
						itemList: ['发送给朋友', '保存图片', '收藏'],
						success: function(data) {
							console.log('选中了第' + (data.tapIndex + 1) + '个按钮,第' + (data.index + 1) + '张图片');
						},
						fail: function(err) {
							console.log(err.errMsg);
						}
					}
				});
			}
		},
		getPhoneNumber(e) {
			let that = this
			// this.getwxCode()
			that.loginInfo.mobilecode = e.detail.code
			uni.login({
				provider: 'weixin',
				onlyAuthorize: true,
				success: function(loginRes) {
					that.loginInfo.code = loginRes.code
					if (that.loginInfo.mobilecode) {
						that.wxLogin()
					}
				}
			});
		},
		wxLogin() {
			let that = this
			index.wxLogin(this.loginInfo).then(res => {
				uni.setStorage({
					key: 'userInfo',
					data: res.data.userinfo,
					success: function() {
						that.userInfo = res.data.userinfo
						// uni.$emit('company', {
						// 	msg: '页面更新'
						// })
					}
				})
				uni.setStorage({
					key: 'token',
					data: res.data.userinfo.token,
					success: function() {
						that.token = res.data.userinfo.token
						that.getUserInfo()
						uni.showToast({
							icon: 'none',
							title: '登录成功',
							duration: 2000
						});

					}
				});
			})
		},
	}
}